﻿using NewChillers.Models;
using NewChillers.ViewModels;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;

namespace NewChillers.Views
{
    /// <summary>
    /// ManualControlPage.xaml 的交互逻辑
    /// </summary>
    public partial class ManualControlPage : UserControl
    {
        public ManualControlPage(UserModel userModel, ShellViewModel shellViewModel)
        {
            var viewmodel = new ManualControlViewModel(userModel, shellViewModel);
            this.DataContext = viewmodel;

            InitializeComponent();
        }

        /// <summary>
        /// 输入框获取焦点时，清空默认值
        private void TextBox_GotFocus(object sender, RoutedEventArgs e)
        {
            var textBox = sender as TextBox;
            if (textBox != null)
            {
                if (textBox.Tag == null)
                {
                    textBox.Tag = textBox.Text; // 保存默认值
                }

                if (string.IsNullOrWhiteSpace(textBox.Text) || textBox.Text == (string)textBox.Tag)
                {
                    textBox.Text = "";
                    textBox.Foreground = Brushes.Black; // 将文本颜色改为黑色
                }
            }
        }
        /// <summary>
        /// 输入框失去焦点时，并且没有修改恢复默认值
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void TextBox_LostFocus(object sender, RoutedEventArgs e)
        {
            var textBox = sender as TextBox;
            if (textBox != null && string.IsNullOrWhiteSpace(textBox.Text))
            {
                textBox.Text = (string)textBox.Tag; // 恢复默认值
                textBox.Foreground = Brushes.LightGray; // 将文本颜色改回浅色
            }
        }

    }
}
